var OutpatientManagement = {
    id: "OutpatientManagementTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

OutpatientManagement.initColumn = function () {// 初始化表格的列
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '门诊名称', field: 'outpatientName', align: 'center', valign: 'middle', sortable: true},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true},
        {title: '排序', visible: false, field: 'num', align: 'center', valign: 'middle', sortable: true},
    ];
};

OutpatientManagement.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        OutpatientManagement.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加渠道
 */
OutpatientManagement.openAddOutpatientManagement = function () {
    var index = layer.open({
        type: 2,
        title: '添加渠道',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/outpatientManagement/outpatientManagement_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看渠道详情
 */
OutpatientManagement.openOutpatientManagementDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '部门详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/outpatientManagement/outpatientManagement_update/' + OutpatientManagement.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除渠道
 */
OutpatientManagement.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/outpatientManagement/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            OutpatientManagement.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
OutpatientManagement.formParams = function () {
    var queryData = {};
    queryData['outpatientName'] = $("#outpatientName").val();
    return queryData;
}

OutpatientManagement.resetSearch = function () {
    $("#outpatientName").val("");
    OutpatientManagement.search();
};

/**
 * 查询列表
 */
OutpatientManagement.search = function () {
    OutpatientManagement.table.refresh({query: OutpatientManagement.formParams()});
};

$(function () {
    var defaultColunms = OutpatientManagement.initColumn();
    var table = new BSTable(OutpatientManagement.id, "/outpatientManagement/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(OutpatientManagement.formParams());
    OutpatientManagement.table = table.init();
    OutpatientManagement.table = table;
});
